//Luogu:392844 the second year in CSP-S rp++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,m,L,V,cam[200001],sum,s[200001],c[200001];
ll A,B,C;
vector<ll> v[10001];
struct car{
    ll d,v,a;
    ll lg=-1,rg=-1;//from pos lg-rg the car'speed>V
    bool f=0;
}a[200001];
ll todo(){
    vector<ll> ca;
    ca.clear();
    for(ll i=1;i<=n;i++)
        if(a[i].f){
            bool flag=0;
            for(auto&&j:v[i]){
                for(auto&&k:ca){
                    if(j==k){flag=1;break;}
                }
                if(flag) break;
            }
            if(ca.empty() || !flag) ca.push_back(v[i][0]);
            else continue;
        }
    return ca.size();
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        A=B=C=0;
        sum=0;
        memset(s,0,sizeof s);
        memset(c,0,sizeof c);
        scanf("%lld %lld %lld %lld",&n,&m,&L,&V);
        for(ll i=1;i<=n;i++) scanf("%lld %lld %lld",&a[i].d,&a[i].v,&a[i].a);
        for(ll i=1;i<=m;i++) scanf("%lld",cam+i),c[cam[i]]=1;
        sort(cam+1,cam+m+1);
        for(ll i=1;i<=n;i++){
            if(a[i].a==0){
                A++;
                if(a[i].v<=V) continue;
                a[i].lg=a[i].d,a[i].rg=cam[m]+1;
                ll pos=*upper_bound(cam+1,cam+m+1,a[i].d);
                if(a[i].d<=pos){
                    a[i].f=1;
                    sum++;
                }
            }
            else if(a[i].a>0){
                B++;
                ll a1=V*V-a[i].v*a[i].v,b1=2*a[i].a,x=a[i].d;
                x+=a1/b1+1;
                a[i].lg=x,a[i].rg=cam[m]+1;
                ll pos=*upper_bound(cam+1,cam+m+1,x);
                if(x<=pos){
                    a[i].f=1;
                    sum++;
                }
            }
            else{
                C++;
                if(a[i].v<=V) continue;
                ll a1=V*V-a[i].v*a[i].v,b1=2*a[i].a,x=a[i].d;//x means where the car's speed is higher than the V.
                if(a1%b1==0) x+=a1/b1-1;
                else x+=a1/b1;
                a[i].lg=a[i].d,a[i].rg=x;
                ll pos=*upper_bound(cam+1,cam+m+1,a[i].d);
                if(a[i].lg<=pos && a[i].rg>=pos){
                    a[i].f=1;
                    sum++;
                }
            }

        }
        ll res=0;
        if(n<=3000 && m<=3000){
            for(ll i=1;i<=n;i++)
                if(a[i].f)
                    for(ll j=a[i].lg;j<=a[i].rg;j++)
                        if(c[j]) v[i].push_back(j);

            res=todo();
        }
        else{
            res=0;
        }
        printf("%lld %lld\n",sum,m-res);
    }

    return 0;
}
/*
14:52 finish reading
15:02 don't completely think of the std so I'll read T3
15:08 maybe T3 is a hard dp so I choose T2
15:33 T3'example in PDF was wrongXD
15:58 ans 1 is all Ac but ans 2 I can't solve it
17:45 I CANNOT SOLVE IT
nlogn to solve the first problem and don't know how to do next:((((((((((((((
rp++;
*/
